﻿//-------------
// <copyright file="IUserRepository.cs" company="Uncas">
//     Copyright (c) Ole Lynge Sørensen. All rights reserved.
// </copyright>
//-------------

namespace Uncas.Katas.SimpleMembership.Domain
{
    using System.Collections.Generic;
    using System.Diagnostics.CodeAnalysis;
    using System.Web.Security;

    /// <summary>
    /// Repository for user data.
    /// </summary>
    public interface IUserRepository
    {
        /// <summary>
        /// Adds the user to role.
        /// </summary>
        /// <param name="userName">The user name.</param>
        /// <param name="roleName">Name of the role.</param>
        void AddUserToRole(string userName, string roleName);

        /// <summary>
        /// Changes the password.
        /// </summary>
        /// <param name="userName">The user name.</param>
        /// <param name="password">The password.</param>
        void ChangePassword(string userName, string password);

        /// <summary>
        /// Creates the role.
        /// </summary>
        /// <param name="roleName">Name of the role.</param>
        void CreateRole(string roleName);

        /// <summary>
        /// Creates the user.
        /// </summary>
        /// <param name="userName">The user name.</param>
        /// <param name="password">The password.</param>
        /// <param name="email">The email.</param>
        void CreateUser(string userName, string password, string email);

        /// <summary>
        /// Deletes the user.
        /// </summary>
        /// <param name="userName">The user name.</param>
        void DeleteUser(string userName);

        /// <summary>
        /// Gets all role names.
        /// </summary>
        /// <returns>The role names.</returns>
        [SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate",
            Justification = "Queries database.")]
        IEnumerable<string> GetAllRoleNames();

        /// <summary>
        /// Gets all roles.
        /// </summary>
        /// <returns>The roles.</returns>
        [SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate",
            Justification = "Queries database.")]
        IEnumerable<Role> GetAllRoles();

        /// <summary>
        /// Gets the roles for user.
        /// </summary>
        /// <param name="userName">The user name.</param>
        /// <returns>The roles for the given user.</returns>
        IEnumerable<string> GetRolesForUser(string userName);

        /// <summary>
        /// Gets the user.
        /// </summary>
        /// <param name="userName">The user name.</param>
        /// <returns>The given user.</returns>
        MembershipUser GetUser(string userName);

        /// <summary>
        /// Gets the users.
        /// </summary>
        /// <returns>The users.</returns>
        [SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate",
            Justification = "Queries database.")]
        IEnumerable<User> GetUsers();

        /// <summary>
        /// Gets the users in role.
        /// </summary>
        /// <param name="roleName">Name of the role.</param>
        /// <returns>The users in the given role.</returns>
        IEnumerable<string> GetUsersInRole(string roleName);

        /// <summary>
        /// Determines whether [is user in role] [the specified userName].
        /// </summary>
        /// <param name="userName">The user name.</param>
        /// <param name="roleName">Name of the role.</param>
        /// <returns>
        /// <c>true</c> if [is user in role] [the specified userName]; otherwise, <c>false</c>.
        /// </returns>
        bool IsUserInRole(string userName, string roleName);

        /// <summary>
        /// Removes the user from role.
        /// </summary>
        /// <param name="userName">The user name.</param>
        /// <param name="roleName">Name of the role.</param>
        void RemoveUserFromRole(string userName, string roleName);

        /// <summary>
        /// Updates the user.
        /// </summary>
        /// <param name="userName">The user name.</param>
        /// <param name="email">The email.</param>
        /// <param name="isApproved">if set to <c>true</c> [is approved].</param>
        void UpdateUser(string userName, string email, bool isApproved);

        /// <summary>
        /// Validates the credentials.
        /// </summary>
        /// <param name="userName">Name of the user.</param>
        /// <param name="password">The password.</param>
        /// <returns>True if the credentials are valid, otherwise false.</returns>
        bool ValidateCredentials(string userName, string password);
    }
}
